﻿#include "Sandbox.h"
#include <glm/gtc/type_ptr.hpp>
#include "cairo/cairo.h"


SandboxLayer::SandboxLayer()
:m_cube_color_(1.0, 1.0, 0.5, 1.0), m_camera_controller_(1280.0f / 720.0f)
{
	m_texture_2d_ = DM::Texture2D::Create("assets/textures/Checkerboard.png");
}



void SandboxLayer::OnUpdate(DM::Timestep ts)
{
	DM::Renderer2D::ResetStats();
	{
		DM::RenderCommand::Clear();
		DM::RenderCommand::SetClearColor({ 0.1f,0.1f,0.1f,1.0f });
	}
	DM::Renderer2D::BeginScene(m_camera_controller_.GetCamera());
	DM::Renderer2D::DrawQuad({ -1.0f, 0.0f }, { 0.8f, 0.8f }, m_texture_2d_, 1.0f, { m_cube_color_.x, m_cube_color_.y, m_cube_color_.z, m_cube_color_.w });
	DM::Renderer2D::EndScene();
}

void SandboxLayer::OnImGuiRender()
{
	ImGui::Begin("Settings");

	auto stats = DM::Renderer2D::GetStats();
	ImGui::Text("Renderer2D Stats:");
	ImGui::Text("Draw Calls: %d", stats.DrawCalls);
	ImGui::Text("Quads: %d", stats.QuadCount);
	ImGui::Text("Vertices: %d", stats.GetTotalVertexCount());
	ImGui::Text("Indices: %d", stats.GetTotalIndexCount());

	ImGui::ColorEdit4("color", glm::value_ptr(m_cube_color_));
	ImGui::End();
}

void SandboxLayer::OnEvent(DM::Event & event)
{
	cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 10, 10);
	cairo_t* cr = cairo_create(surface);
	m_camera_controller_.OnEvent(event);
}